package com.view.houseon;

import java.util.ArrayList;

import com.controller.houseon.ControlHouseON;
import com.model.houseon.TipoDispositivoBean;
import com.presentacion.houseon.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class ListaTipoDispositivosActivity extends Activity {

	ListView lstTD;
	ArrayList<TipoDispositivoBean>lista;
	
	static final int id_demo=4;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lista_tipo_dispositivos);
		
		lstTD =(ListView) findViewById(R.id.lstTDispositivos);
		
		lista= ControlHouseON.getInstancia().ListaTipoDispostivo();
		ItemTipoDispositivoAdapter item= new ItemTipoDispositivoAdapter(ListaTipoDispositivosActivity.this, lista);
		lstTD.setAdapter(item);
		
		lstTD.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> l, View v, int position,
					long id) {
				// TODO Auto-generated method stub
				//Toast.makeText(ListaTipoDispositivosActivity.this,String.valueOf("id:" +id), Toast.LENGTH_SHORT).show();
				
				if(ControlHouseON.getInstancia().CurrentUsuario.getTipoUsuario().getIdTipoUsuario()!=id_demo){
					Intent i = new Intent(ListaTipoDispositivosActivity.this, ListaDispositivosxTipoActivity.class);
					i.putExtra("idTD", (int) id);
					startActivity(i);
					}
					else{
						
						Intent i = new Intent(ListaTipoDispositivosActivity.this, ListaDispositivosxTipoDemoActivity.class);
						i.putExtra("idTD", (int) id);
						startActivity(i);
					}
				
			}
			
		} );
		
		
		/*lstTD.setOnTouchListener(new OnTouchListener(){

			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				  Log.d("Manoj", "onTouch entered");
				  Toast.makeText(ListaTipoDispositivosActivity.this,String.valueOf("onTouch entered"), Toast.LENGTH_SHORT).show();
	              if(event.getAction() == MotionEvent.ACTION_UP) {
	                  Log.d("Manoj", "ACTION_UP");
	                  Toast.makeText(ListaTipoDispositivosActivity.this,String.valueOf("ACTION_UP"), Toast.LENGTH_SHORT).show();
	               //   v.setPressed(true);
	                  int x = (int) event.getX();
	                  int y = (int) event.getY(); 

	              }
	              return false;
			}
	      });*/
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lista_tipo_dispositivos, menu);
		return true;
	}

}
